/******/ (function(modules) {
  // webpackBootstrap
  /******/ // The module cache
  /******/ var installedModules = {}; // The require function
  /******/
  /******/ /******/ function __webpack_require__(moduleId) {
    /******/
    /******/ // Check if module is in cache
    /******/ if (installedModules[moduleId]) {
      /******/ return installedModules[moduleId].exports;
      /******/
    } // Create a new module (and put it into the cache)
    /******/ /******/ var module = (installedModules[moduleId] = {
      /******/ i: moduleId,
      /******/ l: false,
      /******/ exports: {}
      /******/
    }); // Execute the module function
    /******/
    /******/ /******/ modules[moduleId].call(
      module.exports,
      module,
      module.exports,
      __webpack_require__
    ); // Flag the module as loaded
    /******/
    /******/ /******/ module.l = true; // Return the exports of the module
    /******/
    /******/ /******/ return module.exports;
    /******/
  } // expose the modules object (__webpack_modules__)
  /******/
  /******/
  /******/ /******/ __webpack_require__.m = modules; // expose the module cache
  /******/
  /******/ /******/ __webpack_require__.c = installedModules; // define getter function for harmony exports
  /******/
  /******/ /******/ __webpack_require__.d = function(exports, name, getter) {
    /******/ if (!__webpack_require__.o(exports, name)) {
      /******/ Object.defineProperty(exports, name, {
        enumerable: true,
        get: getter
      });
      /******/
    }
    /******/
  }; // define __esModule on exports
  /******/
  /******/ /******/ __webpack_require__.r = function(exports) {
    /******/ if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
      /******/ Object.defineProperty(exports, Symbol.toStringTag, {
        value: "Module"
      });
      /******/
    }
    /******/ Object.defineProperty(exports, "__esModule", { value: true });
    /******/
  }; // create a fake namespace object // mode & 1: value is a module id, require it // mode & 2: merge all properties of value into the ns // mode & 4: return value when already ns object // mode & 8|1: behave like require
  /******/
  /******/ /******/ /******/ /******/ /******/ /******/ __webpack_require__.t = function(
    value,
    mode
  ) {
    /******/ if (mode & 1) value = __webpack_require__(value);
    /******/ if (mode & 8) return value;
    /******/ if (
      mode & 4 &&
      typeof value === "object" &&
      value &&
      value.__esModule
    )
      return value;
    /******/ var ns = Object.create(null);
    /******/ __webpack_require__.r(ns);
    /******/ Object.defineProperty(ns, "default", {
      enumerable: true,
      value: value
    });
    /******/ if (mode & 2 && typeof value != "string")
      for (var key in value)
        __webpack_require__.d(
          ns,
          key,
          function(key) {
            return value[key];
          }.bind(null, key)
        );
    /******/ return ns;
    /******/
  }; // getDefaultExport function for compatibility with non-harmony modules
  /******/
  /******/ /******/ __webpack_require__.n = function(module) {
    /******/ var getter =
      module && module.__esModule
        ? /******/ function getDefault() {
            return module["default"];
          }
        : /******/ function getModuleExports() {
            return module;
          };
    /******/ __webpack_require__.d(getter, "a", getter);
    /******/ return getter;
    /******/
  }; // Object.prototype.hasOwnProperty.call
  /******/
  /******/ /******/ __webpack_require__.o = function(object, property) {
    return Object.prototype.hasOwnProperty.call(object, property);
  }; // __webpack_public_path__
  /******/
  /******/ /******/ __webpack_require__.p = ""; // Load entry module and return exports
  /******/
  /******/
  /******/ /******/ return __webpack_require__(
    (__webpack_require__.s = "./mvvm/my-mvvm/main.js")
  );
  /******/
})(
  /************************************************************************/
  /******/ {
    /***/ "./mvvm/my-mvvm/compile.js":
      /*!*********************************!*\
  !*** ./mvvm/my-mvvm/compile.js ***!
  \*********************************/
      /*! exports provided: default */
      /***/ function(module, __webpack_exports__, __webpack_require__) {
        "use strict";
        eval(
          '__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Compile; });\n/* harmony import */ var _watcher_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./watcher.js */ "./mvvm/my-mvvm/watcher.js");\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\nvar Compile =\n/*#__PURE__*/\nfunction () {\n  function Compile(el, vm) {\n    _classCallCheck(this, Compile);\n\n    this.vm = vm;\n    this.el = el;\n    this.fragment = null;\n    this.init();\n  }\n\n  _createClass(Compile, [{\n    key: "init",\n    value: function init() {\n      this.el = this.isElementNode(this.el) ? this.el : document.querySelector(this.el);\n      this.fragment = this.node2fragment(this.el);\n      this.compile(this.fragment);\n      this.el.appendChild(this.fragment);\n    } // 生成dom片段\n\n  }, {\n    key: "node2fragment",\n    value: function node2fragment(el) {\n      var fragment = document.createDocumentFragment();\n      var child = el.firstChild;\n\n      while (child) {\n        fragment.appendChild(child);\n        child = el.firstChild;\n      }\n\n      return fragment;\n    } // 编译\n\n  }, {\n    key: "compile",\n    value: function compile(fragment) {\n      var _this = this;\n\n      var childNode = fragment.childNodes;\n      var reg = /\\{\\{(.*)\\}\\}/;\n      Array.from(childNode).forEach(function (child) {\n        var text = child.textContent;\n\n        if (_this.isElementNode(child)) {\n          // 元素节点\n          _this.compileElement(child);\n        } else if (_this.isTextNode(child) && reg.test(text)) {\n          // 文本节点\n          _this.compileText(child, reg.exec(text)[1]);\n        }\n\n        if (child.childNodes && child.childNodes.length) {\n          _this.compile(child);\n        }\n      });\n    } // 编译元素节点\n\n  }, {\n    key: "compileElement",\n    value: function compileElement(node) {\n      var _this2 = this;\n\n      var attrs = node.attributes;\n      Array.from(attrs).forEach(function (attr) {\n        var dir = attr.name; // 是否为指令\n\n        if (_this2.isDirective(dir)) {\n          var exp = attr.value;\n          dir = dir.substring(2); // 事件指令\n\n          if (_this2.isDirEvent(dir)) {\n            _this2.compileEvent(node, dir, exp);\n          } // v-model指令\n\n\n          if (_this2.isDirModel(dir)) {\n            _this2.compileModel(node, dir, exp);\n          } // ...\n\n\n          node.removeAttribute(attr.name);\n        }\n      });\n    } // 编译文本节点\n\n  }, {\n    key: "compileText",\n    value: function compileText(node, exp) {\n      var _this3 = this;\n\n      var initText = this.vm[exp]; // 初始化文本节点\n\n      this.updaterText(node, initText); // 监听数据变化,更新文本节点\n\n      new _watcher_js__WEBPACK_IMPORTED_MODULE_0__["default"](this.vm, exp, function (value) {\n        _this3.updaterText(node, value);\n      });\n    } // 编译事件\n\n  }, {\n    key: "compileEvent",\n    value: function compileEvent(node, dir, exp) {\n      var eventType = dir.split(\':\')[1];\n      var fn = this.vm.$options.methods && this.vm.$options.methods[exp];\n      if (!eventType || !fn) return;\n      node.addEventListener(eventType, fn.bind(this.vm), false);\n    } // 编译v-model\n\n  }, {\n    key: "compileModel",\n    value: function compileModel(node, dir, exp) {\n      var _this4 = this;\n\n      var value = this.vm[exp];\n      this.updateModel(node, value);\n      node.addEventListener(\'input\', function (e) {\n        var newVal = e.target.value;\n        if (value === newVal) return;\n        value = newVal;\n        _this4.vm[exp] = value;\n      });\n    } // 更新文本节点\n\n  }, {\n    key: "updaterText",\n    value: function updaterText(node, value) {\n      node.textContent = typeof value === \'undefined\' ? \'\' : value;\n    } // 更新v-model节点\n\n  }, {\n    key: "updateModel",\n    value: function updateModel(node, value) {\n      node.value = typeof value === \'undefined\' ? \'\' : value;\n    } // 判断指令 事件 元素 文本\n\n  }, {\n    key: "isDirective",\n    value: function isDirective(dir) {\n      return dir.indexOf(\'v-\') === 0;\n    }\n  }, {\n    key: "isDirModel",\n    value: function isDirModel(dir) {\n      return dir.indexOf(\'model\') === 0;\n    }\n  }, {\n    key: "isDirEvent",\n    value: function isDirEvent(dir) {\n      return dir.indexOf(\'on:\') === 0;\n    }\n  }, {\n    key: "isElementNode",\n    value: function isElementNode(node) {\n      return node.nodeType === 1;\n    }\n  }, {\n    key: "isTextNode",\n    value: function isTextNode(node) {\n      return node.nodeType === 3;\n    }\n  }]);\n\n  return Compile;\n}();\n\n\n\n//# sourceURL=webpack:///./mvvm/my-mvvm/compile.js?'
        );

        /***/
      },

    /***/ "./mvvm/my-mvvm/dep.js":
      /*!*****************************!*\
  !*** ./mvvm/my-mvvm/dep.js ***!
  \*****************************/
      /*! exports provided: default */
      /***/ function(module, __webpack_exports__, __webpack_require__) {
        "use strict";
        eval(
          '__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Dep; });\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar Dep =\n/*#__PURE__*/\nfunction () {\n  function Dep(props) {\n    _classCallCheck(this, Dep);\n\n    this.subs = [];\n  }\n\n  _createClass(Dep, [{\n    key: "addSub",\n    value: function addSub(sub) {\n      this.subs.push(sub);\n    }\n  }, {\n    key: "notify",\n    value: function notify() {\n      this.subs.forEach(function (sub) {\n        sub.update();\n      });\n    }\n  }]);\n\n  return Dep;\n}();\n\n\nDep.target = null;\n\n//# sourceURL=webpack:///./mvvm/my-mvvm/dep.js?'
        );

        /***/
      },

    /***/ "./mvvm/my-mvvm/main.js":
      /*!******************************!*\
  !*** ./mvvm/my-mvvm/main.js ***!
  \******************************/
      /*! exports provided: default */
      /***/ function(module, __webpack_exports__, __webpack_require__) {
        "use strict";
        eval(
          "__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return MVVM; });\n/* harmony import */ var _observer_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./observer.js */ \"./mvvm/my-mvvm/observer.js\");\n/* harmony import */ var _compile_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./compile.js */ \"./mvvm/my-mvvm/compile.js\");\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\nvar LIFE_CYCLE = ['beforeCreate', 'create', 'beforeMount', 'mounted', 'beforeUpdate', 'updated', 'beforeDestroy', 'destroy'];\n\nvar MVVM =\n/*#__PURE__*/\nfunction () {\n  function MVVM(props) {\n    _classCallCheck(this, MVVM);\n\n    this.$options = props;\n    this._data = this.$options.data;\n    this._el = this.$options.el; // 数据劫持挂载在最外层\n\n    this._proxyData();\n\n    _observer_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"].create(this._data);\n    new _compile_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this._el, this);\n    this.setHook('mounted');\n  }\n\n  _createClass(MVVM, [{\n    key: \"_proxyData\",\n    value: function _proxyData() {\n      var _this = this;\n\n      var data = this._data;\n      var self = this;\n      Object.keys(data).forEach(function (key) {\n        Object.defineProperty(_this, key, {\n          enumerable: true,\n          configurable: true,\n          get: function get() {\n            return data[key];\n          },\n          set: function set(newVal) {\n            if (data[key] === newVal) return;\n            data[key] = newVal;\n            self.setHook('updated');\n          }\n        });\n      });\n    }\n  }, {\n    key: \"setHook\",\n    value: function setHook(name) {\n      if (!LIFE_CYCLE.find(function (val) {\n        return val === name;\n      })) return;\n      this.$options[name] && this.$options[name].call(this);\n    }\n  }]);\n\n  return MVVM;\n}();\n\n\n\nfunction action() {\n  window.$vm = new MVVM({\n    el: '#app',\n    data: {\n      title: 'hello mvvm',\n      name: 'jtr',\n      count: 0\n    },\n    methods: {\n      add: function add() {\n        this.count++;\n      }\n    },\n    mounted: function mounted() {\n      var _this2 = this;\n\n      this.timer = setInterval(function () {\n        _this2.title += '*';\n      }, 500);\n    },\n    updated: function updated() {\n      this.title.length > 20 && clearInterval(this.timer);\n    }\n  });\n}\n\naction();\n\n//# sourceURL=webpack:///./mvvm/my-mvvm/main.js?"
        );

        /***/
      },

    /***/ "./mvvm/my-mvvm/observer.js":
      /*!**********************************!*\
  !*** ./mvvm/my-mvvm/observer.js ***!
  \**********************************/
      /*! exports provided: default */
      /***/ function(module, __webpack_exports__, __webpack_require__) {
        "use strict";
        eval(
          '__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Observer; });\n/* harmony import */ var _dep_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./dep.js */ "./mvvm/my-mvvm/dep.js");\nfunction _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\nvar Observer =\n/*#__PURE__*/\nfunction () {\n  function Observer(data) {\n    _classCallCheck(this, Observer);\n\n    this.data = data;\n    this.init();\n  }\n\n  _createClass(Observer, [{\n    key: "init",\n    value: function init() {\n      var _this = this;\n\n      var data = this.data;\n      Object.keys(data).forEach(function (key) {\n        _this.defineReactive(data, key, data[key]);\n      });\n    }\n  }, {\n    key: "defineReactive",\n    value: function defineReactive(data, key, value) {\n      var dep = new _dep_js__WEBPACK_IMPORTED_MODULE_0__["default"]();\n      /** 子属性为对象 **/\n\n      Observer.create(value);\n      Object.defineProperty(data, key, {\n        enumerable: true,\n        configurable: true,\n        get: function get() {\n          /**添加watcher**/\n          if (_dep_js__WEBPACK_IMPORTED_MODULE_0__["default"].target) {\n            dep.addSub(_dep_js__WEBPACK_IMPORTED_MODULE_0__["default"].target);\n          }\n\n          return value;\n        },\n        set: function set(newVal) {\n          if (newVal === value) return;\n          value = newVal;\n          /** 赋值后为对象 **/\n\n          Observer.create(value);\n          /**通知watcher**/\n\n          dep.notify(); // console.log(\'set\', key)\n        }\n      });\n    }\n  }], [{\n    key: "create",\n    value: function create(value) {\n      if (!value || _typeof(value) !== \'object\') return;\n      new Observer(value);\n    }\n  }]);\n\n  return Observer;\n}();\n\n\n\n//# sourceURL=webpack:///./mvvm/my-mvvm/observer.js?'
        );

        /***/
      },

    /***/ "./mvvm/my-mvvm/watcher.js":
      /*!*********************************!*\
  !*** ./mvvm/my-mvvm/watcher.js ***!
  \*********************************/
      /*! exports provided: default */
      /***/ function(module, __webpack_exports__, __webpack_require__) {
        "use strict";
        eval(
          '__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return Watcher; });\n/* harmony import */ var _dep_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./dep.js */ "./mvvm/my-mvvm/dep.js");\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\nvar Watcher =\n/*#__PURE__*/\nfunction () {\n  function Watcher(vm, exp, cb) {\n    _classCallCheck(this, Watcher);\n\n    this.vm = vm;\n    this.exp = exp;\n    this.cb = cb;\n    this.value = this.get();\n  }\n\n  _createClass(Watcher, [{\n    key: "get",\n    value: function get() {\n      _dep_js__WEBPACK_IMPORTED_MODULE_0__["default"].target = this;\n      var value = this.vm[this.exp]; // new Watcher时强制添加\n\n      _dep_js__WEBPACK_IMPORTED_MODULE_0__["default"].target = null;\n      return value;\n    }\n  }, {\n    key: "update",\n    value: function update() {\n      this.run();\n    }\n  }, {\n    key: "run",\n    value: function run() {\n      var value = this.vm[this.exp];\n      var oldVal = this.value;\n      if (oldVal === value) return;\n      this.value = value;\n      this.cb && this.cb.call(this.vm, value, oldVal);\n    }\n  }]);\n\n  return Watcher;\n}();\n\n\n\n//# sourceURL=webpack:///./mvvm/my-mvvm/watcher.js?'
        );

        /***/
      }

    /******/
  }
);
